/*
---
name: MooDialog.Request
description: Loads Data into a Dialog with Request
authors: Arian Stolwijk
license:  MIT-style license
requires: [MooDialog, Core/Request.HTML]
provides: MooDialog.Request
...
*/

MooDialog.Request = new Class({

	Extends: MooDialog,
        options: {
		okText: 'Ok',
		focus: true,
		textPClass: 'MooDialogAlert'
	},
        
	initialize: function(url, requestOptions, options){
		this.parent(options);
		this.requestOptions = requestOptions || {};
                
                var okButton = new Element('button', {
			events: {
				click: this.close.bind(this)
			},
			text: this.options.okText,
                        styles:{
                            display : 'none'
                        }
		   });
                
		this.addEvent('open', function(){
			var request = new Request.HTML(this.requestOptions).addEvent('success', function(text){
				this.setContent(text,
                                 new Element('div.buttons').adopt(okButton)
                                   );
			}.bind(this)).send({
				url: url
			});
		}.bind(this));

		if (this.options.autoOpen) this.open();
                
	},

	setRequestOptions: function(options){
		this.requestOptions = Object.merge(this.requestOptions, options);
                
		return this;
	}

});
